// var MongoClient = require('mongodb').MongoClient; // 引入mongodb控制模块
// var DB_BOOKS = 'mongodb://localhost:27017/books'; // 数据库
// module.exports = MongoClient;

// 导入数据
var insertData = function(db, callback) {
  //连接到表 site
  var collection = db.collection('booksList');
  //插入数据
  var data = [{"name":"菜鸟教程","url":"www.runoob.com"},{"name":"菜鸟工具","url":"c.runoob.com"}];
  collection.insert(data, function(err, result) {
    if(err)
    {
      console.log('Error:'+ err);
      return;
    }
    callback(result);
  });
}

MongoClient.connect(DB_BOOKS, function(err, db) {
  console.log("连接成功！");
  insertData(db, function(result) {
    console.log(result);
    db.close();
  });
});
